<template>
  <div>
    <div class="container">
      <el-form ref="query" :model="query" :inline="true" size="mini">
        <el-form-item label="邮箱：" prop="mail">
          <el-input
              v-model="query.mail"
              placeholder="请填写邮箱"
              clearable
          ></el-input>
        </el-form-item>

        <el-button size="mini" type="primary" icon="el-icon-search" @click="handleSearch"
        >搜索
        </el-button
        >
        <el-button size="mini" type="primary" icon="el-icon-delete" @click="handleClear"
        >清空
        </el-button
        >
      </el-form>

      <el-table
          :data="records"
          border
          class="table"
          ref="multipleTable"
          header-cell-class-name="table-header"
      >
        <el-table-column prop="mail" label="邮箱"></el-table-column>
        <el-table-column prop="captcha" label="验证码"></el-table-column>
        <el-table-column prop="expireTime" label="过期时间"></el-table-column>
        <el-table-column label="是否使用" align="center">
          <template #default="scope">
            <el-tag
                :type="
                scope.row.used === true
                  ? 'success'
                  : scope.row.used === false
                  ? 'danger'
                  : 'info'
              "
            >{{
                $enum.getMapValue("yesNo", scope.row.used).name
              }}
            </el-tag
            >
          </template>
        </el-table-column>
        <el-table-column prop="useTime" label="使用时间"></el-table-column>
        <el-table-column prop="createdTime" label="创建时间"></el-table-column>
        <el-table-column label="操作" width="180" align="center">
          <template #default="scope">
            <el-button
                type="text"
                icon="el-icon-info"
                @click="handleInfo(scope.$index, scope.row)"
                v-if="$perm.hasPerm('button_mailCaptchaLog_detail')"
            >详情
            </el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <custom-page
            :current="query.current"
            :size="query.size"
            :total="total"
            @current-change="handlePageChange"
        />
      </div>
    </div>

    <!-- 详情弹出框 -->
    <el-dialog :title="详情" v-model="editVisible" width="50%" @closed="closed">
      <el-form :model="form" label-width="150px">
        <el-form-item label="邮箱：">
          <div v-text="form.mail"></div>
        </el-form-item>
        <el-form-item label="验证码：">
          <div v-text="form.captcha"></div>
        </el-form-item>
        <el-form-item label="过期时间：">
          <div v-text="form.expireTime"></div>
        </el-form-item>
        <el-form-item label="是否使用：">
          <div>{{ $enum.getMapValue("yesNo", form.used).name }}</div>
        </el-form-item>
        <el-form-item label="使用时间：">
          <div v-text="form.useTime"></div>
        </el-form-item>
        <el-form-item label="创建时间：">
          <div v-text="form.createdTime"></div>
        </el-form-item>
        <el-form-item label="更新时间：">
          <div v-text="form.modifiedTime"></div>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="editVisible = false">关闭</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import {mailCaptchaLogDetailApi, mailCaptchaLogPageApi} from "../../api/log/mailCaptchaLog";

export default {
  data() {
    return {
      query: {
        current: 1,
        size: 10,
        mail: null,
      },
      records: [],
      multipleSelection: [],
      delList: [],
      editVisible: false,
      total: 0,
      form: {},
      idx: -1,
      id: -1,
    };
  },
  created() {
    this.getData();
  },
  methods: {
    // 获取数据
    getData() {
      mailCaptchaLogPageApi(this.query).then((res) => {
        this.records = res?.bizData?.records;
        this.total = res?.bizData?.total;
      });
    },
    // 触发搜索按钮
    handleSearch() {
      this.query.current = 1;
      this.getData();
    },
    // 清空
    handleClear() {
      if (this.$refs.query != undefined) {
        this.$refs.query.resetFields();
        this.getData();
      }
    },
    // 详情操作
    handleInfo(index, row) {
      this.idx = index;
      mailCaptchaLogDetailApi({id: row.id}).then((res) => {
        this.form = res?.bizData;
      });
      this.editVisible = true;
    },
    // 添加 编辑弹出层关闭动画结束操作
    closed() {
      this.idx = -1;
      this.form = deepCopy(obj);
    },
    // 分页导航
    handlePageChange(val) {
      this.query.current = val;
      this.getData();
    },
  },
};
</script>

<style scoped>
.handle-box {
  margin-bottom: 20px;
}

.handle-input {
  width: 300px;
  display: inline-block;
}

.table {
  width: 100%;
  font-size: 14px;
}

.red {
  color: #ff0000;
}

.mr10 {
  margin-right: 10px;
}

.table-td-thumb {
  display: block;
  margin: auto;
  width: 40px;
  height: 40px;
}
</style>
